#ifndef OBJECT_H
#define OBJECT_H

#include <QVector>

class QString;
class QVector3D;
class QVector2D;

class Face;
class Material;

class Object
{

public:
    Object();
    ~Object();

    bool isValid() const;
    bool isLoadedGPU() const;

    qreal width() const;
    qreal height() const;
    qreal depth() const;
    qreal minX() const;
    qreal maxX() const;
    qreal minY() const;
    qreal maxY() const;
    qreal minZ() const;
    qreal maxZ() const;

    const QVector< Material* >& materials() const;
    const QVector< const QVector3D* >& vertices() const;
    const QVector< const QVector3D* >& normals() const;
    const QVector< const QVector2D* >& UVs() const;
    const QVector< const Face* >& faces() const;

    bool loadOBJ(const QString& rkFileName);
    void unloadOBJ();

    void loadGPU();
    void unloadGPU();

private:
    typedef enum
    {
        OBJ_UNKNOWN,
        MTL_LIBRARY,
        MTL_USE,
        VERTEX,
        UV,
        NORMAL,
        FACE
    } OBJToken;

    typedef enum
    {
        MTL_UNKNOWN,
        AMBIENT,
        DIFFUSE,
        SPECULAR,
        SHININESS,
        AMBIENT_TEXTURE,
        DIFFUSE_TEXTURE,
        SPECULAR_TEXTURE
    } MTLToken;

    static OBJToken toOBJToken(const QString& rkToken);
    static MTLToken toMTLToken(const QString& rkToken);

    bool loadMTL(const QString& rkFileName);

    //------------------------------------------------
    //  Attributes.
    //------------------------------------------------
    // File data.
    bool                        m_bIsValid;

    QString                     m_kRootDir;
    QString                     m_kObjectFileName;
    QString                     m_kMaterialFileName;

    // Object data.
    qreal m_minX, m_maxX;
    qreal m_minY, m_maxY;
    qreal m_minZ, m_maxZ;

    QVector< Material* >        m_kMaterials;
    QVector< const QVector3D* > m_kVertices;
    QVector< const QVector3D* > m_kNormals;
    QVector< const QVector2D* > m_kUVs;
    QVector< const Face* >      m_kFaces;

    // OpenGL.
    bool m_bIsLoadedGPU;
};

#endif // OBJECT_H
